<meta charset='utf-8'>
<?php
class DB
{
	private $conn;
	private $result;
	public function __construct()
	{
		//echo "Succuess constructed<br/>";
		$this->conn=mysql_connect("localhost",'sql_flyingwings','woshifpl');
		
	}
	public function getDB($db)
	{
		mysql_select_db($db);
		//echo "successfully selected<br/>";
	}
	public function select($from/*选择的表*/,$object='*'/*选择的东西*/,$where='1')
	{
		$this->result=mysql_query("select ".$object." from ".$from." where ".$where);   //select clause
		if(!$this->result)
		{
			$this->result="";
			header('Location: http://www.baidu.com/');
			//重定向到错误页面
		}
		else
		{
			$res= array();
			while($get=mysql_fetch_array($this->result))
			{
				array_push($res,$get);
			}
			return $res;
			
			//返回的是所有数据的数组
			//如result[0]['user_id'];
		}
			
	}
	public function update($table/*表*/,$object/*要设置的对象*/,$value/*设置的值*/,$where="1")
	{
		$result=mysql_query("update ".$table." SET ".$object." = ".$value."where ".$where);
		if($result) echo "失败";
		else echo "更新结果成功";
	}
	
	public function delete($table,$where)
	{
		$result=mysql_query("delete from ".$table." where ".$where);
		if($result) echo "失败";
		else echo "删除结果成功";
	}
	
	public function insert($table,$values="")
	{
		$form="";
		$rescolumns = mysql_query("SHOW FULL COLUMNS FROM ".$table."") ;
		while($row = mysql_fetch_array($rescolumns))
		{
			$form=$form.$row['Field'].",";
		}
		$form = substr($form,0,strlen($form)-1);
		echo $form;
	
		mysql_query("insert into ".$table." (".$form.") VALUES (".$values.")"); //插入写好
	}
}

/*
$a= new DB();
$a->getDB('sql_flyingwings');
echo $a->select("User")[0]['password'];
//mysql_query("update User set password = '333' where user_id = '123' ");
$a->update('User','password',"333","user_id='123'");
$a->insert("User","'fpl','fpl','fpl'");
*/